//
//  YLSelectPhotoCell.m
//  DEMOTest
//
//  Created by mac on 2020/5/9.
//  Copyright © 2020 mac. All rights reserved.
//

#import "YLSelectPhotoCell.h"


@implementation TJSelectPhotoModel
 

+ (instancetype)selectPhotoModel:(nullable UIImage *)image isAdd:(BOOL)Add isShowDelete:(BOOL)showDelete {
    TJSelectPhotoModel *model = [[TJSelectPhotoModel alloc] init];
    model.isAdd = Add;
    model.isShowDelete = showDelete;
    model.image = image;
    return model;
}

@end



@interface YLSelectPhotoCell()
 
@property (weak, nonatomic) UIImageView *addImageView;
@property (weak, nonatomic) UIImageView *imageView;
@property (weak, nonatomic) UIButton *deleteButton;

@end


@implementation YLSelectPhotoCell


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
    
        self.backgroundColor = UIColor.whiteColor;
        self.contentView.backgroundColor = UIColor.whiteColor;

        UIView *tj_contentView = [UIView tj_addToView:self];
        [tj_contentView shearRoundedCornersWithRadiu:3];
        tj_contentView.backgroundColor = UIColor_Hex(0xF4F9FF);
        [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.right.offset(-10);
            make.left.bottom.offset(0);
        }];
        
        UIImageView *imageView = [UIImageView tj_addToView:tj_contentView];
        [imageView shearRoundedCornersWithRadiu:3];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.offset(0);
        }];
        
        UIImageView *addImageView = [UIImageView tj_addToView:tj_contentView];
        addImageView.image = [UIImage imageNamed:@"camera_icon"];
         [addImageView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.width.offset(44);
             make.height.offset(38);
             make.center.offset(0);
        }];
        
        
        UIButton *deleteButton = [UIButton tj_addToView:self];
        [deleteButton setBackgroundImage:[UIImage imageNamed:@"appeal_delete"] forState:UIControlStateNormal];
        [deleteButton addTarget:self action:@selector(didClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
        [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(imageView.mas_right);
            make.centerY.equalTo(imageView.mas_top);
            make.width.height.offset(20);
        }];
         
        _addImageView = addImageView;
        _imageView = imageView;
        _addImageView.hidden = YES;
        _deleteButton = deleteButton;
        
    }
    return self;
}

- (void)didClickDeleteButton {
    if (_didClickDeleteButtonBlock) {
        _didClickDeleteButtonBlock();
    }
}


- (void)setModel:(TJSelectPhotoModel *)model {
    _model = model;
    
     _addImageView.hidden = !model.isAdd;
    _imageView.hidden = model.isAdd;
    _imageView.image = model.image;
    _deleteButton.hidden = !model.image;
 
}

@end

 
